package cn.qidisoft.edu.hzjt.controller.zyc;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FilenameUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.qidisoft.core.common.context.ApplicationContextConfigUtil;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.DateUtil;
import cn.qidisoft.core.util.file.FileUtil;
import cn.qidisoft.core.util.moffice.excel.ExpExcelUtil;
import cn.qidisoft.core.util.uuid.UUIDGenerator;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.exception.RPCException;
import cn.qidisoft.edu.hzjt.model.BjxxClassMaterialFile;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.model.xb.PartyResponsibilityAttEn;
import cn.qidisoft.edu.hzjt.model.zyc.PartyActivity;
import cn.qidisoft.edu.hzjt.model.zyc.PartyActivityComment;
import cn.qidisoft.edu.hzjt.model.zyc.PartyActivityMember;
import cn.qidisoft.edu.hzjt.model.zyc.PartyLeagueMember;
import cn.qidisoft.edu.hzjt.service.zyc.IDyService;
import cn.qidisoft.edu.hzjt.service.zyc.IPartyActivityService;
import cn.qidisoft.edu.hzjt.utils.CommonUtils;
import cn.qidisoft.edu.hzjt.utils.LogType;

/***
 * 活动/会议名称控制器
 * 7.3.1、固定日活动
 * 7.3.2、社区服务与志愿参与
 * 7.6、宣传思想工作情况
 * 7.7.3、廉政建设分析会材料
 * @Author Vincent
 * @date 2018-11-16
 */
@Controller
@RequestMapping(value="/partyActivity/")
public class PartyActivityController {

	protected static final LoggerAdapter LOGGER =
			LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);

	private static String upload = null;
	static {
		upload = ApplicationContextConfigUtil.getString("file.path", null);
	}

	private static Map<String, List<PartyResponsibilityAttEn>> picMap = new HashMap<>();

	@Autowired
	private IPartyActivityService partyActivityService;

	@Autowired
	private IDyService dyService;

	/***
	 * 跳转到列表页面
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "list")
	public String list(HttpServletRequest request){
		String hdType = request.getParameter("hdType");
		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		request.setAttribute("partyFixedDateActivityDay",partyFixedDateActivityDay);
		request.setAttribute("hdType",hdType);

		request.setAttribute("msg", BaseController.getParameter("msg"));
		BaseController.removeParameter("msg");

		return "zyc/partyActivity/list";
	}

	/***
	 * 查询分页数据
	 * @param model
	 * @param request
	 * @param pageSize
	 * @param currentPage
	 * @return
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public ResponseResult listData(ModelMap model, HttpServletRequest request,
			@RequestParam(value = "rows", required = false) String pageSize,
			@RequestParam(value = "page", required = false) String currentPage) {
		try {
			Page page = new Page();
			page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
			page.setPageSize(pageSize == null ? 10 : Integer.valueOf(pageSize));
			BaseController.setSortByColumn(request, "hDID", "asc");
			String hdType = request.getParameter("hdType");
			String hDMC = request.getParameter("hDMC");
			String hDZT = request.getParameter("hDZT");
			String bdate = request.getParameter("bdate");
			String edate = request.getParameter("edate");
			Map<String,Object> paramtersMap = new HashMap<String,Object>();
			paramtersMap.put("orderField",(String) request.getAttribute("orderField"));
			paramtersMap.put("orderFlag",(String) request.getAttribute("orderFlag"));
			paramtersMap.put("hDMC",hDMC);
			paramtersMap.put("hDZT",hDZT);
			paramtersMap.put("bdate",bdate);
			paramtersMap.put("edate",edate);
			paramtersMap.put("hdType",hdType);
			PaginationBean<PartyActivity> paginationBean = partyActivityService.queryPartyActivityPageList(paramtersMap,page);
			ResponseResult result = new ResponseResult();
			result.setTotal(paginationBean.getTotalRecords());
			result.setRows(paginationBean.getPageList());
			return result;
		} catch (Exception e) {
			LOGGER.error("获得 listData [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
		}
		return null;
	}

	/***
	 * 跳转到添加页面
	 * @return
	 */
	@RequestMapping(value = "preadd")
	public String preadd(HttpServletRequest request){
		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		if(partyFixedDateActivityDay != null && partyFixedDateActivityDay.length()==1){
			request.setAttribute("partyFixedDateActivityDay","0" + partyFixedDateActivityDay);
		}else{
			request.setAttribute("partyFixedDateActivityDay", partyFixedDateActivityDay);
		}

		// 获取党员信息(党籍状态为正常1)
		Map<String, Object> queryMap = new HashMap<String,Object>();
		PartyLeagueMember partyLeagueMember = new PartyLeagueMember();
		partyLeagueMember.setdJZT("1");
		queryMap.put("PartyLeagueMember", partyLeagueMember);
		List<PartyLeagueMember> partyLeagueMembers = dyService.getDybList(queryMap);
		//request.setAttribute("partyLeagueMemberJson", JSON);
		try {
			ObjectMapper mapper = new ObjectMapper();
			String json = mapper.writeValueAsString(partyLeagueMembers);
			System.out.println("json===="+json);
			request.setAttribute("json", json);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		request.setAttribute("partyLeagueMember", partyLeagueMembers);
		String hdType = request.getParameter("hdType");
		request.setAttribute("hdType",hdType);
		return "zyc/partyActivity/add";
	}

	@RequestMapping(value = "/getdy")
	@ResponseBody
	public List<PartyLeagueMember> getdy(){
		Map<String, Object> queryMap = new HashMap<String,Object>();
		PartyLeagueMember partyLeagueMember = new PartyLeagueMember();
		partyLeagueMember.setdJZT("1");
		queryMap.put("PartyLeagueMember", partyLeagueMember);
		List<PartyLeagueMember> partyLeagueMembers = dyService.getDybList(queryMap);
		return partyLeagueMembers;
	}

	/***
	 * 添加
	 * @return
	 */
	@RequestMapping(value = "add")
	public String add(HttpServletRequest request, String addType, Integer hdType,PartyActivity partyActivity, HttpSession session){
		try {
			UserEmployee user = (UserEmployee) session.getAttribute(Constant.LOGIN_CONSOLE_USER);
			partyActivity.setCreatorId(user.getEmid());
			partyActivity.setCreatorName(user.getName());
			partyActivity.setCreateTime(DateUtil.formatDate2Str((new Date()), DateUtil.YYYY_MM_DD_FORMAT));
			partyActivity.sethdType(hdType);
			partyActivityService.addPartyActivity(partyActivity);
			BaseController.setParameter("msg", "添加成功");
		} catch (Exception e) {
			LOGGER.error("操作 add [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
		}
		if(addType.equals("2")){//保存并添加
			return "redirect:./preadd?hdType="+hdType;
		}else{//保存
			return "redirect:./list?hdType="+hdType;
		}
	}


	/***
	 * 跳转到修改页面
	 * @return
	 */
	@RequestMapping(value = "/premodify")
	public String premodify(HttpServletRequest request,Integer id){

		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		if(partyFixedDateActivityDay.length()==1){
			request.setAttribute("partyFixedDateActivityDay","0" + partyFixedDateActivityDay);
		}else{
			request.setAttribute("partyFixedDateActivityDay", partyFixedDateActivityDay);
		}

		String hdType = request.getParameter("hdType");
		request.setAttribute("hdType",hdType);
		PartyActivity partyActivity = partyActivityService.getPartyActivityById(id);
		//请假人员和参与人员存这里，没有区分（添加功能中区分了、用两个不同的List来存储）
		List<PartyActivityMember> allList = partyActivity.getPartyActivityMembers();
		List<PartyActivityMember> partyActivityMembers = new ArrayList<PartyActivityMember>();
		List<PartyActivityMember> partyActivityMembersQingjia = new ArrayList<PartyActivityMember>();
		for(int i = 0;i<allList.size();i++){
			PartyActivityMember partyActivityMember = allList.get(i);
			if(partyActivityMember.getMemberType()==1){
				partyActivityMembers.add(partyActivityMember);
			}else if(partyActivityMember.getMemberType()==2){
				partyActivityMembersQingjia.add(partyActivityMember);
			}
		}

		try {
			// 获取党员信息(党籍状态为正常1)
			Map<String, Object> queryMap = new HashMap<String,Object>();
			PartyLeagueMember partyLeagueMember = new PartyLeagueMember();
			partyLeagueMember.setdJZT("1");
			queryMap.put("PartyLeagueMember", partyLeagueMember);
			List<PartyLeagueMember> partyLeagueMembers = dyService.getDybList(queryMap);
			ObjectMapper mapper = new ObjectMapper();
			String json = mapper.writeValueAsString(partyLeagueMembers);
			request.setAttribute("json", json);
			request.setAttribute("partyLeagueMember", partyLeagueMembers);

			ObjectMapper mapper1 = new ObjectMapper();
			String  partyActivityMembersJSON = mapper1.writeValueAsString(partyActivityMembers);
			ObjectMapper mapper2 = new ObjectMapper();
			String  partyActivityMembersQingjiaJSON = mapper2.writeValueAsString(partyActivityMembersQingjia);
			request.setAttribute("partyActivityMembersJSON", partyActivityMembersJSON + "");
			System.out.println("partyActivityMembersJSON==="+partyActivityMembersJSON);
			System.out.println("json==="+json);
			System.out.println("partyActivityMembersQingjiaJSON==="+partyActivityMembersQingjiaJSON);
			request.setAttribute("partyActivityMembersQingjiaJSON", partyActivityMembersQingjiaJSON + "");


			//获取附件信息
			PartyResponsibilityAttEn att = new PartyResponsibilityAttEn();
			att.setParentId(id);
			List<PartyResponsibilityAttEn> attList = partyActivityService.queryFilesList(att);
			request.setAttribute("dataList", attList);

		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		request.setAttribute("partyActivity",partyActivity);
		request.setAttribute("partyActivityMembers",partyActivityMembers);
		request.setAttribute("partyActivityMembersQingjia",partyActivityMembersQingjia);
		return "zyc/partyActivity/modify";
	}

	/***
	 * 修改
	 * @return
	 */
	@RequestMapping(value = "/modify")
	public String modify(String addType, Integer hdType,PartyActivity partyActivity){
		try {
			partyActivity.sethdType(hdType);
			partyActivityService.updatePartyActivity(partyActivity);
			BaseController.setParameter("msg", "修改成功");
		} catch (Exception e) {
			LOGGER.error("操作 add [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
		}
		if(addType.equals("2")){//保存并添加
			return "redirect:./preadd?hdType="+hdType;
		}else{//保存
			return "redirect:./list?hdType="+hdType;
		}
	}



	/***
	 * 修改
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public String delete(HttpServletRequest request,Integer[] hDID){
		String[] ids = request.getParameterValues("hDID");
		partyActivityService.delete(hDID);
		BaseController.setParameter("msg", "删除成功");
		return "redirect:./list";
	}


	/**
	 *
	 * @Title: loadFile
	 * @Description: 附件上传
	 * @param @param file
	 * @param @param request
	 * @param @param response    参数
	 * @return void    返回类型
	 * @throws
	 */
	@RequestMapping(value = "/source_upload", method = RequestMethod.POST)
	public @ResponseBody void source_upload(@RequestParam("file") MultipartFile file,
			HttpServletRequest request, HttpServletResponse response) {
		List<PartyResponsibilityAttEn> list = new ArrayList<>();
		UserEmployee userEnrollee = (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
		List<PartyResponsibilityAttEn> docFileResourceList = picMap
				.get(String.valueOf(userEnrollee.getUserid()));
		// 本地env配置路径
		String path = upload;
		try {
			String gid = UUID.randomUUID().toString();
			String name = file.getOriginalFilename();// 获取上传文件名
			// 获取文件后缀名称
			String extend = FilenameUtils.getExtension(name);
			PartyResponsibilityAttEn docFile = new PartyResponsibilityAttEn();
			if (!file.isEmpty()) {
				// 文件的大小
				docFile.setFileSize(String.valueOf(FileUtil.FormetFileSize(Long.valueOf(file.getSize()))));
				docFile.setFileName(name);
				docFile.setGid(gid);
				docFile.setFilePath(gid + CommonUtils.fileSeprator+ gid + "." + extend);
				docFile.setExtension(FileUtil.getFileExtendName(name).toLowerCase());
				docFile.setMufile(file);
				docFile.setInputStream(file.getInputStream());
				docFile.setSysfilepath(path + CommonUtils.fileSeprator+ gid + CommonUtils.fileSeprator+ gid + "." + extend);
				docFile.setOrders(0);
				if (docFileResourceList != null && docFileResourceList.size() > 0) {
					docFileResourceList.add(docFile);
					picMap.put(String.valueOf(userEnrollee.getUserid()), docFileResourceList);
				} else {
					list.add(docFile);
					picMap.put(String.valueOf(userEnrollee.getUserid()), list);
				}
				LOGGER.info("附件上传成功！");
			}
			PrintWriter writer = null;
			BjxxClassMaterialFile docFile2 = new BjxxClassMaterialFile();
			docFile2.setFilepath(docFile.getFilePath());
			// 文件名称
			docFile2.setFilename(docFile.getFileName());
			docFile2.setSysfilepath(path + CommonUtils.fileSeprator+ gid + CommonUtils.fileSeprator+ gid + "." + extend);
			writer = response.getWriter();
			String json = JSONObject.toJSONString(docFile2);
			writer.write(json);
			writer.flush();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	/***
	 * 修改
	 * @return
	 */
	@RequestMapping(value = "/saveActivityAtt")
	public String saveActivityAtt(HttpServletRequest request,String addType, Integer hdType,PartyActivity partyActivity){
		try {
			partyActivity.sethdType(hdType);
			UserEmployee userEmployee = (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
			String gid = UUIDGenerator.genReqID();
			partyActivity.setgID("");
			partyActivity.setCreatorId(userEmployee.getUid());
			partyActivity.setCreatorName(userEmployee.getXm());
			partyActivity.setCreateTime(DateUtil.formatDate2Str((new Date()), DateUtil.YYYY_MM_DD_FORMAT));
			String path = upload;
			List<PartyResponsibilityAttEn> docFileResourceList = picMap.get(String.valueOf(userEmployee.getUserid()));
			if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
				MultipartFile file = null;
				for (PartyResponsibilityAttEn r : docFileResourceList) {
					file = r.getMufile();
					r.setParentId(partyActivity.gethDID());
					String name = file.getOriginalFilename();// 获取上传文件名
					InputStream in = r.getInputStream();// 获取文件对象
					int pos = name.lastIndexOf(".");
					String lastname = name.substring(pos, name.length());
					// 文件保存的路径
					String savePath = path + CommonUtils.fileSeprator+ r.getGid();
					FileUtil.saveFile(savePath, in, r.getGid() + lastname);
					r.setGid(r.getGid());// 附件id
					r.setFileName(name);
					r.setParentId(partyActivity.gethDID());
				}
				partyActivityService.batchInsertsFiles(docFileResourceList);
				//一旦上传成功需要清空，否则下一次上传的时候又刚一遍了~
				picMap.remove(String.valueOf(userEmployee.getUserid()));
			}

			partyActivityService.updatePartyActivityObject(partyActivity);

		} catch (Exception e) {
			e.printStackTrace();
			LOGGER.error("添加信息 add [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			return "error/error";
		}
		if(addType.equals("2")){//保存并添加
			return "redirect:./preadd?hdType="+hdType;
		}else{//保存
			return "redirect:./list?hdType="+hdType;
		}
	}



	/***
	 * 保存评论内容
	 * @return
	 */
	@RequestMapping(value = "/addPartyActivityComment")
	public String addPartyActivityComment(HttpServletRequest request, String addType, Integer hdType, PartyActivityComment partyActivityComment){
		try {
			String parentId = request.getParameter("hDID");
			UserEmployee userEmployee = (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
			String gid = UUIDGenerator.genReqID();
			partyActivityComment.setgID(gid);
			partyActivityComment.setdYID(userEmployee.getUid());
			partyActivityComment.setdYXM(userEmployee.getXm());
			partyActivityComment.setCreateTime(new Date());
			partyActivityComment.setParentId(parentId);
			partyActivityService.addPartyActivityComment(partyActivityComment);
			String path = upload;
			List<PartyResponsibilityAttEn> docFileResourceList = picMap.get(String.valueOf(userEmployee.getUserid()));
			if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
				MultipartFile file = null;
				for (PartyResponsibilityAttEn r : docFileResourceList) {
					file = r.getMufile();
					r.setParentId(partyActivityComment.getpJID());
					String name = file.getOriginalFilename();// 获取上传文件名
					InputStream in = r.getInputStream();// 获取文件对象
					int pos = name.lastIndexOf(".");
					String lastname = name.substring(pos, name.length());
					// 文件保存的路径
					String savePath = path + CommonUtils.fileSeprator+ r.getGid();
					FileUtil.saveFile(savePath, in, r.getGid() + lastname);
					r.setGid(r.getGid());// 附件id
					r.setFileName(name);
				}
				partyActivityService.batchInsertsCommentFiles(docFileResourceList);
				//一旦上传成功需要清空，否则下一次上传的时候又刚一遍了~
				picMap.remove(String.valueOf(userEmployee.getUserid()));
			}

		} catch (Exception e) {
			e.printStackTrace();
			LOGGER.error("添加信息 add [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			return "error/error";
		}
		if(addType.equals("2")){//保存并添加
			return "redirect:./preadd?hdType="+hdType;
		}else{//保存
			return "redirect:./list?hdType="+hdType;
		}
	}



	/***
	 * 得到评论分页数据
	 * @param model
	 * @param request
	 * @param pageSize
	 * @param currentPage
	 * @return
	 */
	@RequestMapping(value = "listCommentsData")
	@ResponseBody
	public PaginationBean<PartyActivityComment> listCommentsData(ModelMap model, HttpServletRequest request,
			@RequestParam(value = "rows", required = false) String pageSize,
			@RequestParam(value = "page", required = false) String currentPage) {
		try {
			Page page = new Page();
			page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
			page.setPageSize(pageSize == null ? 10 : Integer.valueOf(pageSize));
			BaseController.setSortByColumn(request, "pJID", "asc");
			String hDID = request.getParameter("hDID");
			Map<String,Object> paramtersMap = new HashMap<String,Object>();
			paramtersMap.put("orderField",(String) request.getAttribute("orderField"));
			paramtersMap.put("orderFlag",(String) request.getAttribute("orderFlag"));
			paramtersMap.put("hDID",hDID);
			PaginationBean<PartyActivityComment> paginationBean = partyActivityService.queryPartyActivityCommentsPageList(paramtersMap,page);
			return paginationBean;
		} catch (Exception e) {
			LOGGER.error("获得 listCommentsData [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
		}
		return null;
	}


	/***
	 * 设置规定日活动
	 * @return
	 */
	@RequestMapping(value = "setPartyFixedDateActivityDay")
	@ResponseBody
	public String setPartyFixedDateActivityDay(Integer partyFixedDateActivityDay){
		try{
			partyActivityService.setPartyFixedDateActivityDay(partyFixedDateActivityDay);
			return "1";
		} catch (Exception e){
			LOGGER.error("操作失败 setPartyFixedDateActivityDay [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			return "0";
		}
	}


	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); // true:允许输入空值，false:不能为空值
	}


	/************************************************************华丽的分隔符******************************************************************************/
	/**
	 * 
	 * @Title: add   
	 * @Description: 详情页面
	 * 1、点击标题的超链接直接看详情
	 * 2、新增页面点击“保存”按钮跳转
	 * @param @param model
	 * @param @param request
	 * @param @return    参数   
	 * @return String    返回类型   
	 * @throws
	 */
	@RequestMapping(value = "/info", method = RequestMethod.GET)
	public String info(ModelMap model, HttpServletRequest request) {
		//获取详情
		String id = request.getParameter("id") == null ? "0" : request.getParameter("id");

		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		if(partyFixedDateActivityDay.length()==1){
			request.setAttribute("partyFixedDateActivityDay","0" + partyFixedDateActivityDay);
		}else{
			request.setAttribute("partyFixedDateActivityDay", partyFixedDateActivityDay);
		}

		String hdType = request.getParameter("hdType");
		request.setAttribute("hdType",hdType);
		PartyActivity partyActivity = partyActivityService.getPartyActivityById(Integer.parseInt(id));
		//请假人员和参与人员存这里，没有区分（添加功能中区分了、用两个不同的List来存储）


		List<PartyActivityMember> allList = partyActivity.getPartyActivityMembers();

		//参与人员
		List<PartyActivityMember> partyActivityMembers = new ArrayList<PartyActivityMember>();
		//请假人员
		List<PartyActivityMember> partyActivityMembersQingjia = new ArrayList<PartyActivityMember>();

		for(int i = 0;i<allList.size();i++){
			PartyActivityMember partyActivityMember = allList.get(i);
			if(partyActivityMember.getMemberType()==1){
				partyActivityMembers.add(partyActivityMember);
			}else if(partyActivityMember.getMemberType()==2){
				partyActivityMembersQingjia.add(partyActivityMember);
			}
		}

		try {
			// 获取党员信息(党籍状态为正常1)
			Map<String, Object> queryMap = new HashMap<String,Object>();
			PartyLeagueMember partyLeagueMember = new PartyLeagueMember();
			partyLeagueMember.setdJZT("1");
			queryMap.put("PartyLeagueMember", partyLeagueMember);
			List<PartyLeagueMember> partyLeagueMembers = dyService.getDybList(queryMap);
			ObjectMapper mapper = new ObjectMapper();
			String json = mapper.writeValueAsString(partyLeagueMembers);
			request.setAttribute("json", json);
			request.setAttribute("partyLeagueMember", partyLeagueMembers);

			request.setAttribute("partyActivityMembers", partyActivityMembers);
			request.setAttribute("partyActivityMembersQingjia", partyActivityMembersQingjia);


			//获取附件信息
			PartyResponsibilityAttEn att = new PartyResponsibilityAttEn();
			att.setParentId(Integer.parseInt(id));
			List<PartyResponsibilityAttEn> attList = partyActivityService.queryFilesList(att);
			request.setAttribute("dataList", attList);


		} catch (JsonProcessingException e) {
			e.printStackTrace();

			LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			model.addAttribute(Constant.EXPTION_MSG_KEY, e);
			return "error/error";
		}

		request.setAttribute("partyActivity",partyActivity);
		request.setAttribute("partyActivityMembers",partyActivityMembers);
		request.setAttribute("partyActivityMembersQingjia",partyActivityMembersQingjia);

		return "zyc/partyActivity/info";
	}

	/**
	 * 
	 * @Title: exportpartyEmploySupervise   
	 * @Description: 列表数据导出
	 * @param @param request
	 * @param @param response
	 * @param @param data
	 * @param @param model
	 * @param @return
	 * @param @throws Exception    参数   
	 * @return String    返回类型   
	 * @throws
	 */
	@RequestMapping(value = "/exportPartyActivity")
	public @ResponseBody String exportPartyActivity(HttpServletRequest request,
			HttpServletResponse response, PartyActivity data, ModelMap model) throws Exception {
		try {
			String hdType = request.getParameter("hdType");
			String hDMC = request.getParameter("hDMC");
			String hDZT = request.getParameter("hDZT");
			String bdate = request.getParameter("bdate");
			String edate = request.getParameter("edate");
			Map<String,Object> paramtersMap = new HashMap<String,Object>();
			paramtersMap.put("orderField",(String) request.getAttribute("orderField"));
			paramtersMap.put("orderFlag",(String) request.getAttribute("orderFlag"));
			paramtersMap.put("hDMC",hDMC);
			paramtersMap.put("hDZT",hDZT);
			paramtersMap.put("bdate",bdate);
			paramtersMap.put("edate",edate);
			paramtersMap.put("hdType",hdType);
			List<PartyActivity> queryList = partyActivityService.queryList(paramtersMap);

			String[][] title_name = {{"活动名称", "活动日期","活动时间", "活动地点", "活动主题"}};
			String[] title_style = {"hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20"};
			String fileName = "固定日活动";
			if("1".equals(hdType)) {
				fileName = "固定日活动";
			}else if("2".equals(hdType)) {
				fileName = "社区服务与志愿参与";
			}else if("3".equals(hdType)) {
				fileName = "社区服务与志愿参与";
			}else if("4".equals(hdType)) {
				fileName = "宣传思想工作情况";
			}
			String[] remark = {""};
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			if (queryList != null && !queryList.isEmpty()) {
				for (PartyActivity res : queryList) {
					Map<String, Object> map = new LinkedHashMap<String, Object>();
					map.put("hDMC", res.gethDMC());
					map.put("hDRQ", res.gethDRQ());
					map.put("hDSJ", res.gethDSJ());
					map.put("hDDD", res.gethDDD());
					map.put("hDZT", res.gethDZT());
					list.add(map);
				}
			}
			HSSFWorkbook wb = ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark, fileName, list);

			try {
				String filenameConvert = fileName;/* new String(fileName.getBytes("GB2312"), "ISO8859-1"); */
				response.reset();
				response.setContentType("application/vnd.ms-excel;charset=utf-8");
				response.setHeader("Content-Disposition", "attachment;filename="+ new String((filenameConvert + ".xls").getBytes(), "iso-8859-1"));
				response.setDateHeader("Expires", 0);
				ServletOutputStream os = response.getOutputStream();
				wb.write(os);
				os.flush();
			} catch (Exception e) {
				System.out.println("网络连接断开，可能用户取消了导出");
				model.addAttribute(Constant.EXPTION_MSG_KEY, e);
				return "error/error";
			}
		} catch (RPCException e) {
			LOGGER.error("获得数据 exportStudentjobList [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			model.addAttribute(Constant.EXPTION_MSG_KEY, e);
			return "error/error";
		}
		return null;
	}














	/************************************************************华丽的分隔符：个人评价部分******************************************************************************/
	/***
	 * 跳转到列表页面
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/grpj/list")
	public String list2(HttpServletRequest request){
		String hdType = request.getParameter("hdType");
		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		request.setAttribute("partyFixedDateActivityDay",partyFixedDateActivityDay);
		request.setAttribute("hdType",hdType);

		request.setAttribute("msg", BaseController.getParameter("msg"));
		BaseController.removeParameter("msg");

		return "zyc/partyActivity/grpj/list";
	}

	/***
	 * 查询分页数据
	 * @param model
	 * @param request
	 * @param pageSize
	 * @param currentPage
	 * @return
	 */
	@RequestMapping(value = "/grpj/listData")
	@ResponseBody
	public ResponseResult listData2(ModelMap model, HttpServletRequest request,
			@RequestParam(value = "rows", required = false) String pageSize,
			@RequestParam(value = "page", required = false) String currentPage) {
		try {
			Page page = new Page();
			page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
			page.setPageSize(pageSize == null ? 10 : Integer.valueOf(pageSize));
			BaseController.setSortByColumn(request, "hDID", "asc");
			String hdType = request.getParameter("hdType");
			String hDMC = request.getParameter("hDMC");
			String hDZT = request.getParameter("hDZT");
			String bdate = request.getParameter("bdate");
			String edate = request.getParameter("edate");
			Map<String,Object> paramtersMap = new HashMap<String,Object>();
			paramtersMap.put("orderField",(String) request.getAttribute("orderField"));
			paramtersMap.put("orderFlag",(String) request.getAttribute("orderFlag"));
			paramtersMap.put("hDMC",hDMC);
			paramtersMap.put("hDZT",hDZT);
			paramtersMap.put("bdate",bdate);
			paramtersMap.put("edate",edate);
			paramtersMap.put("hdType",hdType);
			PaginationBean<PartyActivity> paginationBean = partyActivityService.queryPartyActivityPageList(paramtersMap,page);
			ResponseResult result = new ResponseResult();
			result.setTotal(paginationBean.getTotalRecords());
			result.setRows(paginationBean.getPageList());
			return result;
		} catch (Exception e) {
			LOGGER.error("获得 listData [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
		}
		return null;
	}

	/***
	 * 跳转到修改页面
	 * @return
	 */
	@RequestMapping(value = "/grpj/premodify")
	public String premodify2(ModelMap model, HttpServletRequest request){

		//获取详情
		String id = request.getParameter("id") == null ? "0" : request.getParameter("id");

		String partyFixedDateActivityDay = partyActivityService.queryPartyFixedDateActivityDay();
		if(partyFixedDateActivityDay.length()==1){
			request.setAttribute("partyFixedDateActivityDay","0" + partyFixedDateActivityDay);
		}else{
			request.setAttribute("partyFixedDateActivityDay", partyFixedDateActivityDay);
		}

		String hdType = request.getParameter("hdType");
		request.setAttribute("hdType",hdType);
		PartyActivity partyActivity = partyActivityService.getPartyActivityById(Integer.parseInt(id));
		//请假人员和参与人员存这里，没有区分（添加功能中区分了、用两个不同的List来存储）


		List<PartyActivityMember> allList = partyActivity.getPartyActivityMembers();

		//参与人员
		List<PartyActivityMember> partyActivityMembers = new ArrayList<PartyActivityMember>();
		//请假人员
		List<PartyActivityMember> partyActivityMembersQingjia = new ArrayList<PartyActivityMember>();

		for(int i = 0;i<allList.size();i++){
			PartyActivityMember partyActivityMember = allList.get(i);
			if(partyActivityMember.getMemberType()==1){
				partyActivityMembers.add(partyActivityMember);
			}else if(partyActivityMember.getMemberType()==2){
				partyActivityMembersQingjia.add(partyActivityMember);
			}
		}

		try {
			// 获取党员信息(党籍状态为正常1)
			Map<String, Object> queryMap = new HashMap<String,Object>();
			PartyLeagueMember partyLeagueMember = new PartyLeagueMember();
			partyLeagueMember.setdJZT("1");
			queryMap.put("PartyLeagueMember", partyLeagueMember);
			List<PartyLeagueMember> partyLeagueMembers = dyService.getDybList(queryMap);
			ObjectMapper mapper = new ObjectMapper();
			String json = mapper.writeValueAsString(partyLeagueMembers);
			request.setAttribute("json", json);
			request.setAttribute("partyLeagueMember", partyLeagueMembers);

			request.setAttribute("partyActivityMembers", partyActivityMembers);
			request.setAttribute("partyActivityMembersQingjia", partyActivityMembersQingjia);


			//获取附件信息
			PartyResponsibilityAttEn att = new PartyResponsibilityAttEn();
			att.setParentId(Integer.parseInt(id));
			List<PartyResponsibilityAttEn> attList = partyActivityService.queryFilesList(att);
			request.setAttribute("dataList", attList);


		} catch (JsonProcessingException e) {
			e.printStackTrace();

			LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			model.addAttribute(Constant.EXPTION_MSG_KEY, e);
			return "error/error";
		}

		request.setAttribute("partyActivity",partyActivity);
		request.setAttribute("partyActivityMembers",partyActivityMembers);
		request.setAttribute("partyActivityMembersQingjia",partyActivityMembersQingjia);

		return "zyc/partyActivity/grpj/modify";
	}



	/***
	 * 保存评论内容
	 * @return
	 */
	@RequestMapping(value = "/grpj/addPartyActivityComment")
	public String addPartyActivityComment2(HttpServletRequest request, String addType, Integer hdType, PartyActivityComment partyActivityComment){
		try {
			String parentId = request.getParameter("hDID");
			UserEmployee userEmployee = (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
			String gid = UUIDGenerator.genReqID();
			partyActivityComment.setgID(gid);
			partyActivityComment.setdYID(userEmployee.getUid());
			partyActivityComment.setdYXM(userEmployee.getXm());
			partyActivityComment.setCreateTime(new Date());
			partyActivityComment.setParentId(parentId);
			partyActivityService.addPartyActivityComment(partyActivityComment);
			String path = upload;
			List<PartyResponsibilityAttEn> docFileResourceList = picMap.get(String.valueOf(userEmployee.getUserid()));
			if (docFileResourceList != null && !docFileResourceList.isEmpty()) {
				MultipartFile file = null;
				for (PartyResponsibilityAttEn r : docFileResourceList) {
					file = r.getMufile();
					r.setParentId(partyActivityComment.getpJID());
					String name = file.getOriginalFilename();// 获取上传文件名
					InputStream in = r.getInputStream();// 获取文件对象
					int pos = name.lastIndexOf(".");
					String lastname = name.substring(pos, name.length());
					// 文件保存的路径
					String savePath = path + CommonUtils.fileSeprator+ r.getGid();
					FileUtil.saveFile(savePath, in, r.getGid() + lastname);
					r.setGid(r.getGid());// 附件id
					r.setFileName(name);
				}
				partyActivityService.batchInsertsCommentFiles(docFileResourceList);
				//一旦上传成功需要清空，否则下一次上传的时候又刚一遍了~
				picMap.remove(String.valueOf(userEmployee.getUserid()));
			}

		} catch (Exception e) {
			e.printStackTrace();
			LOGGER.error("添加信息 add [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(), e.getMessage());
			return "error/error";
		}
		//保存
		return "redirect:./list?hdType="+hdType;
	}

}
